package nqueens.util;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.io.PrintWriter;

public class Debugger {
	
	private static final boolean DEFAULT = true;
	
	private static Debugger instance;

	private boolean on;
	
	private PrintWriter out;
	
	
	public void setOutputStream(OutputStream outputStream) {
		out = new PrintWriter(outputStream);
	}

	private Debugger() {
		setOutputStream(System.out);
		on = DEFAULT;
	}
	
	public void setFile(File file) throws FileNotFoundException {
		setOutputStream(new FileOutputStream(file));
	}
	
	public static Debugger getInstance() {
		if (instance == null) {
			instance = new Debugger();
		}
		return instance;
	}
	
	public void print(String msg) {
		if (on) {
			out.println("[DEBUG]");
			out.println("\t" + msg);
			out.flush();
		}
	}
	
	public void turnOn() {
		on = true;
	}
	
	public void turnOff() {
		on = false;
	}
	
}
